package com.lc.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lc.vo.Girl;
import com.lc.vo.ListSon;
import com.lc.vo.TestVo;

@Controller
@RequestMapping("params")
public class ParamController {

	@ResponseBody
	@RequestMapping("string")
	public String strParam(String id, String name){
		System.out.println("params = id:" + id + ", name: " + name);
		TestVo vo = new TestVo();
		vo.setId(id);
		vo.setName(name);
		return vo.toString();
	}
	
	@ResponseBody
	@RequestMapping("pojo")
	public String pojoParam(TestVo vo) {
		System.out.println("param = " + vo);
		return vo.toString();
	}
	
	@ResponseBody
	@RequestMapping("date")
	public Map<String, Object> dateParam(TestVo vo, @DateTimeFormat(pattern="yyyy-MM-dd hh:mm:ss") Date time) {
		System.out.println("param = " + vo);
		System.out.println("time = " + time);
		Map<String, Object> map = new HashMap<>();
		map.put("param", vo);
		map.put("time", time);
		return map;
	}
	
	@ResponseBody
	@RequestMapping("list")
	public Map<String, Object> listParam(TestVo vo, ListSon son) {
		System.out.println("param = " + vo);
		System.out.println("son = " + son.toString());
		Map<String, Object> map = new HashMap<>();
		map.put("param", vo);
		map.put("son", son);
		return map;
	}
	
	/**
	 * 复杂的pojolist
	 * @param son
	 * @return
	 */
	@ResponseBody
	@RequestMapping("pojolist")
	public Map<String, Object> listParam(ListSon son) {
		System.out.println("son = " + son.toString());
		Map<String, Object> map = new HashMap<>();
		map.put("son", son);
		return map;
	}
	
	@ResponseBody
	@RequestMapping("custom")
	public Map<String, Object> customParam(TestVo vo, ListSon son, @RequestParam("girl") Girl girl) {
		System.out.println("param = " + vo);
		System.out.println("son = " + son.toString());
		System.out.println("girl = " + girl.toString());
		Map<String, Object> map = new HashMap<>();
		map.put("param", vo);
		map.put("son", son);
		map.put("girl", girl);
		return map;
	}
	
	@ResponseBody
	@RequestMapping("/url/{name}")
	public Map<String, Object> customParam(@PathVariable("name") String name) {
		System.out.println("name = " + name);
		Map<String, Object> map = new HashMap<>();
		map.put("name", name);
		return map;
	}
	
	@ResponseBody
	@RequestMapping("/header")
	public Map<String, Object> headerParam(@RequestHeader(name = "model", defaultValue = "1" ) String model) {
		System.out.println("model = " + model);
		Map<String, Object> map = new HashMap<>();
		map.put("model", model);
		return map;
	}
	
}
